﻿using System;
namespace Fanxinglianbiao
{
    class Program
    {
        public class Node<T>
        {
            public Node<T> Next { get; set; }
            public T Data { get; set; }

            public Node(T t)
            {
                Next = null;
                Data = t;
            }
        }

        public class GenericList<T>
        {
            private Node<T> head;
            private Node<T> tail;

            public GenericList()
            {
                tail = head = null;
            }

            public Node<T> Head
            {
                get => head;
            }

            public void Add(T t)
            {
                Node<T> n = new Node<T>(t);
                if (tail == null)
                {
                    head = tail = n;
                }
                else
                {
                    tail.Next = n;
                    tail = n;
                }
            }

            public void ForEach(Action<T> action)
            {
                for (Node<T> n = head; n.Next != null; n = n.Next)
                {
                    action(n.Data);
                }
            }
        }

        static void Main(string[] args)
        {
            GenericList<int> intlist = new GenericList<int>();
            Random random = new Random();
            for (int x = 0; x < 10; x++)
            {
                intlist.Add(random.Next() % 100);
            }
            intlist.ForEach(x => Console.Write(" " + x));//打印
            Console.WriteLine();

            int Max = intlist.Head.Data;
            intlist.ForEach(x => Max = Math.Max(x, Max));//打印
            Console.WriteLine("最大值是：" + Max);

            int Min = intlist.Head.Data;
            intlist.ForEach(x => Min = Math.Min(x, Min));//打印
            Console.WriteLine("最小值是：" + Min);

            int Sum = 0;
            intlist.ForEach(x => Sum += x);//打印
            Console.WriteLine("总和是：" + Sum);

        }
    }
}